package deployr.core;

import java.util.*;

import deployr.domain.*;

public class Upgrade {

	private final StringBuilder stringBuilder = new StringBuilder();

	public Upgrade(final IProject project) {
		for (final IUpdate update : reverted(project.findUpdates())) {
			for (final IDeliverable deliverable : update.deliverables()) {
				stringBuilder.append(deliverable.getName()).append("\n");
			}
		}
	}

	private List<IUpdate> reverted(final Iterable<IUpdate> updates) {
		final List<IUpdate> reverted = new LinkedList<IUpdate>();
		for (final IUpdate update : updates) {
			reverted.add(0, update);
		}
		return reverted;
	}

	@Override
	public String toString() {
		return stringBuilder.toString();
	}
}